var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    allPrice: '',
    orderGoodsList: '',
    orderNmae: '',
    mobile: '',
    address: '',
    addtime:'',
  },
  onLoad: function (options) {
    var that = this;
    const userid = app.globalData.userid;
    const orderId = options.orderId
    if(orderId == undefined){
      const list = JSON.parse(options.goodsList)
      that.data.allPrice = 0;
      for (const goodslist of list) {
        that.data.allPrice += goodslist.goodsNumber * goodslist.goodsPrice
        that.data.addtime = goodslist.addTime
      }
      console.log(that.data.addtime)
      that.setData({
        goods: list,
        allPrice: that.data.allPrice,
        addTime: that.data.addtime,
      })
    }else{
      wx.request({
        url: app.globalData.url + 'getOrderByOrderId',
        data: {
          orderId: orderId
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function(res) {
          that.setData({
            goods: res.data.object,
            addTime: res.data.object[0].addTime,
            allPrice: res.data.object[0].goodsAmount,
            orderNum: res.data.object[0].orderSn,
          })
        },
        fail: function(res) {},
        complete: function(res) {},
      })
    }
    wx.request({
      url: app.globalData.url + 'getMemberAddressByUserId',
      data: {
        userId: userid,
        isdefaultaddress: 1
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        that.setData({
          userAddress: res.data.object
        })
        that.data.orderNmae = res.data.object[0].consignee
        that.data.mobile = res.data.object[0].mobile
        that.data.address = res.data.object[0].address
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  orderDetail:function(){
    wx.navigateTo({
      url: '../orderDeatail/orderDeatail',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  /**
   * 复制按钮
   */
  copyBtn:function(e){
    const orderNum = e.currentTarget.dataset.text   
    wx.setClipboardData({
      data: orderNum,
      success: function(res) {
        console.log(res)
        // wx.getClipboardData({
        //   success: function(res) {
        //     console.log(res.data)
        //   },
        //   fail: function(res) {},
        //   complete: function(res) {},
        // })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  /**
  * 修改地址
  */
  changeAddress: function (e) {
    wx.navigateTo({
      url: '../mine/address/address',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  }
})